<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" v-bind="layout" :model="model" :rules="validatorRules">
        <a-form-model-item label="号源方案名称" required prop="name">
          <a-input placeholder="请输入号源方案名称" v-model="model.name" />
        </a-form-model-item>
        <a-form-model-item label="就诊分钟数(分钟)" required prop="minute">
          <a-input-number placeholder="请输入就诊分钟数(分钟)" v-model="model.minute" style="width: 200px"/>
        </a-form-model-item>
        <a-form-model-item label="时段(分钟)" required>
          <a-input-number placeholder="请输入多少分钟为一个时段(分钟)" v-model="model.timeSpan" style="width: 200px" />
        </a-form-model-item>
        <a-form-model-item label="可预约人数" required>
          <a-input-number placeholder="请输入可预约人数" v-model="model.allowQty" style="width: 200px" />
        </a-form-model-item>
      </a-form-model>
    </a-spin>
  </j-modal>
</template>

<script>
import JFormContainer from '@/components/jeecg/JFormContainer'
import JDate from '@/components/jeecg/JDate'
import { httpAction } from '@api/manage'
import moment from "moment"
export default {
  name: 'TimeConfigModal',
  components: {
    JFormContainer,
    JDate
  },
  data() {
    return {
      title: '',
      width: 800,
      visible: false,
      disableSubmit: false,
      confirmLoading: false,
      form: this.$form.createForm(this),
      model: {},
      layout: {
        labelCol: { span: 6 },
        wrapperCol: { span: 14 }
      },
      validatorRules: {
        name: [
          { required: true, message: '请输入源号时段!' }
        ],
      },
      url: {
        addOrEdIt: "/his/time/config",
      },
      bgTimeStrTimePicker: '',
      endTimeStrTimePicker: '',
    }
  },
  methods: {
    moment,
    // onChangeBgMealTime(time, timeString) {
    //   this.bgTimeStrTimePicker = timeString
    // },
    // onChangeEndMealTime(time, timeString) {
    //   this.endTimeStrTimePicker = timeString
    // },
    add() {
      this.edit({});
    },
    edit(record) {
      this.visible = true
      this.model = Object.assign({}, record);

      // let bgConfigTime = record.bgConfigTime;//供餐开始时间
      // let endConfigTime = record.endConfigTime;//供餐结束时间
      // this.bgTimeStrTimePicker = moment(bgConfigTime).format('HH:mm');//YYYY-MM-DD HH:mm:ss
      // this.endTimeStrTimePicker = moment(endConfigTime).format('HH:mm');//YYYY-MM-DD HH:mm:ss

    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    submitCallback() {
      this.$emit('ok')
      this.visible = false
    },
    handleCancel() {
      this.close()
    },
    handleOk() {
      const that = this
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true
          let method = 'post'
          if (this.model.did) {
            method = 'put'
          }
           httpAction(this.url.addOrEdIt, this.model, method).then((res) => {
            if (res.success) {
              that.$message.success(res.message)
              that.$emit('ok')
              that.close()
            } else {
              that.$message.warning(res.message)
            }
          }).finally(() => {
            that.confirmLoading = false
            that.close()
          })
        } else {
          return false
        }
      })
    }
  }
}
</script>